/*
 *@Description: 写日志
 *@Author: panlua
 *@Date: 2019-07-03 09:57:15
*/
const fs = require('fs')
const moment = require('moment')
const writeLog = {
  /*
   *@name: 获取文件名
   *@param:{type} 
   *@description:
   *@return:
   *@author: panlua
   *@date: 2019-07-03 10:16:25
  */
  getData: () => {
    const Y = moment().format('YYYY')
    const M = moment().format('MM')
    const D = moment().format('DD')
    return `${Y}_${M}_${D}.log`
  },
  addBookLog: (item) => {
    return new Promise(async(reslove) => {
      const path = `./logs/addBook/${writeLog.getData()}`
      const content = `书名：${item.title}  作者：${item.author}  类型：${item.majorCate}/${item.minorCate} \n`
      await fs.appendFile(path, content, err => {
              if (err) return LOG.error('日志写入失败：' + err)
            })
      await reslove()
    })
  }
}

module.exports = writeLog